package com.sky.mapper.user;

import com.sky.pojo.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 查询当前(口味)菜品|套餐是否存在
     */
    @Select("select * from shopping_cart where user_id = #{userId} and (setmeal_id = #{setmealId} or dish_id = #{dishId})")
    ShoppingCart queryBySetmealOrDishId(Long userId,Long setmealId,Long dishId);

    /**
     * 数量+1
     * @param id
     * @param
     */
    void updateNum(Long id, int number,String dishFlavor);

    /**
     * 新增购物车
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time) " +
            " values (#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 查看购物车
     * @param currentId
     */
    @Select("select * from shopping_cart where user_id = #{currentId}")
    List<ShoppingCart> queryList(Long currentId);

    @Delete("delete from shopping_cart where user_id = #{currentId}")
    void cleanList(Long currentId);

    Long getTime(Long currentId);
}
